# My pseudo code for Exercice 6
# START
#     s <- a string
#     map <- a dictionary
#     Initialize max_length to 0
#     Initialize left to 0
#     Initialize right to 0
#     FOR each letter in the string:
#         IF letter has appeared then:
#             make the left  to the right of the letter
#             left = max(left, char_map[s[right]] + 1)
#         END IF
#         max_length <- max(max_length, right - left + 1)
#         right <- right+1
#     END FOR
#     Display"Output:{max_length}"
# END
def length_of_longest_substring(s:str):
    char_map = {}
    left = 0 
    max_length = 0  
    for right in range(len(s)):
        if s[right] in char_map:
            left = max(left, char_map[s[right]] + 1)
        char_map[s[right]] = right
        max_length = max(max_length, right - left + 1)
    return max_length
print(length_of_longest_substring("abcabcbb"))
print(length_of_longest_substring("bbbbb"))
